package mysql

import "gorm.io/gorm"

type House struct {
	gorm.Model
	HouseName  string  `gorm:"type:varchar(60)"`
	HousePrice float64 `gorm:"type:decimal(10,2)"`
	HouseType  string  `gorm:"type:varchar(11)"`
	HouseDesc  string  `gorm:"type:varchar(255)"`
	HouseImg   string  `gorm:"type:varchar(255)"`
}

// 分页

func (h *House) Paginate(page int, pageSize int) ([]House, int64, error) {
	var total int64
	var house []House
	offset := (page - 1) * pageSize
	err = Db.Model(House{}).Offset(offset).Limit(pageSize).Find(&house).Error
	if err != nil {
		return nil, 0, err
	}
	err = Db.Model(House{}).Count(&total).Error
	if err != nil {
		return nil, 0, err
	}
	return house, total, nil
}
